package bridge_pattern;

/**
 * 桥接模式
 */
public class Bridge {
  public static void main(String[] args) {
    Paper paper = new ExaminationPaper();
    paper.setPen(new RedPen());
    paper.writing();

    Paper paper2=new NewsPaper();
    paper2.setPen(new BlackPen());
    paper2.writing();
  }

}


interface Pen{
  void write();
}

class RedPen implements Pen{
  public void write() {
    System.out.println("红色的字");
  }
}

class BlackPen implements Pen{
  public void write() {
    System.out.println("黑色的字");
  }
}

abstract class Paper{
  protected Pen pen;

  void setPen(Pen pen){
    this.pen = pen;
  }

  abstract void writing();
}

class ExaminationPaper extends Paper{
  void writing() {
    System.out.println("考试纸 ");
    pen.write();
  }
}

class NewsPaper extends Paper{
  void writing() {
    System.out.println("报纸 ");
    pen.write();
  }
}




